package com.yowasa.xiuxian.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 修仙时间帮助类
 */
public class DateXUtil {
    //时间映射 修仙界一天=现实时间多少秒  12s=一天 一天=20年
    public static final int TIME_MAP = 12;

    //修仙开始的年龄
    public static final int START_AGE = 14;

    private static final SimpleDateFormat FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");


    //获取从当前算起 消耗n天后的时间
    public static Date getTo(int n) {
        Calendar ins = Calendar.getInstance();
        ins.add(Calendar.SECOND, n * TIME_MAP);
        return ins.getTime();
    }

    //获取从某时间开始到现在段经过了多少天
    public static int getFrom(Date from) {
        Calendar ins = Calendar.getInstance();
        long toTime = ins.getTimeInMillis();
        long fromTime = from.getTime();
        return (int) (((toTime - fromTime)) / (1000*TIME_MAP));
    }

    //开始时间和日期 计算结束时间
    public static Date calEndTime(Date start,int days) {
        Calendar ins = Calendar.getInstance();
        ins.setTime(start);
        ins.add(Calendar.SECOND, days * TIME_MAP);
        return ins.getTime();
    }

    /**
     * 获取年龄
     * @param startAt
     * @return
     */
    public static int getAge(Date startAt) {
        Calendar ins = Calendar.getInstance();
        long toTime = ins.getTimeInMillis();
        return START_AGE+(int) ((toTime - startAt.getTime()) / (1000*TIME_MAP * 30 * 12));
    }

    //获取永久时间
    public static Date getMaxTime() {
        Calendar ins = Calendar.getInstance();
        ins.set(Calendar.YEAR,9999);
        return ins.getTime();
    }

    public static String formatTime(Date date) {
        return FORMAT.format(date);
    }


}
